<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="/WEB-INF/tld/path.tld" prefix="p"%>
<html>
<head>
	<title>用户注册</title>

	<p:JSTag file="global.js"></p:JSTag>
	<script type="text/javascript">
	window.onload = function()
	{
		<s:if test="error != ''">
			alert('${error}');
		</s:if>
		<s:if test = "message != ''">
			alert('${message}');
		</s:if>
	}

	/** 重置 **/
	function resetAll()
	{
		var fields = document.getElementsByTagName("input");
		for(i=0;i<fields.length;i++)
		{
			if(fields[i].type == 'text' || fields[i].type == 'password')
			{
				fields[i].value = '';
			}
		}
			
		var textareas = document.getElementsByTagName("textarea");
		for(i=0; i < textareas.length; i++)
		{
			textareas[i].value = '';
		}

		var selects = document.getElementsByTagName("select");
		for(i=0; i < selects.length; i++)
		{
			selects[i].value = '';
		}
	}
	
	/** 返回 **/
	function goBack()
	{
		document.forms[0].action = "login.jsp";
		document.forms[0].submit();
	}
	
	/** 注册 **/
	function register()
	{
		var account = /^([0-9]|[a-z]|[A-Z]){1,15}$/;
		var password = /^([0-9]|[a-z]|[A-Z]){6,20}$/;
		var email = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;

		
		if(trim(document.getElementById("user.loginid").value) == "")
		{
			alert("请输入帐号！");
			return false;
		}
		
		if(!account.test(document.getElementById("user.loginid").value))
		{
			alert("用户帐号：格式错误，合法格式：1-15位数字或字母！");
			return false;
		}

		if(trim(document.getElementById("user.name").value) == "")
		{
			alert("请输入姓名！");
			return false;
		}
		
		if(trim(document.getElementById("user.passwd").value) == "")
		{
			alert("请输入密码！");
			return false;
		}
		
		if(!password.test(document.getElementById("user.passwd").value))
		{
			alert("密码：格式错误，合法格式：6-20位数字或字母！");
			return false;
		}
		
		if(document.getElementById("user.passwd").value != document.getElementById("confirmPsw").value)
		{
			alert("确认密码与密码不一致，请重新输入！");
	        return false;
		}
		
		if(trim(document.getElementById("user.email").value) == "")
		{
			alert("请输入电子邮箱！");
			return false;
		}
		
		if(trim(document.getElementById("user.email").value) != "" && !email.test(document.getElementById("user.email").value))
		{
			alert("请输入正确的Email！");
	        return false;
		}
	
		if(trim(document.getElementById("user.email").value) != "" && (trim(document.getElementById("user.email").value).length<3 || trim(document.getElementById("user.email").value).length>30))
		{
			alert("请输入正确的Email！");
			return false;
		}

		if(trim(document.getElementById("user.descn").value).length > 1024)
		{
			alert("备注：长度错误，合法长度：1024个字符！");
			return false;
		}
		
		document.register_form.submit();
	}
	</script>
</head>
<body>
<form action="user!doRegister.action" method="post" name="register_form" id="register_form">
<table border="0" cellpadding="5" cellspacing="0" align="center">
  <tr> 
    <td valign="top"> 
	<table width="100%" border="0" cellpadding="0" cellspacing="0" class="cTableBorder">
        <tr> 
          <td align="left"  class="window_title">用户注册</td>
        </tr>
        <tr>
          <td align="left">
		  <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
              <tr> 
                <td width="100" class="window_td_left_line">登陆ID</td>
                <td width="500" class="window_td_left_line"> 
                  <input id="user.loginid" name="user.loginid" type="text" class="input_no_long" size="35" maxlength="15">
                  <font color="red">&nbsp; *</font>
                </td>
              </tr>
              <tr> 
                <td width="100" class="window_td_left_line">姓名</td>
                <td class="window_td_left_line"> 
                  <input id="user.name" name="user.name" type="text" class="input_no_long" size="35" maxlength="10" value="<s:property value="user.name"/>">
                  <font color="red">&nbsp; *</font>
                </td>
              </tr>
              <tr> 
                <td class="window_td_left_line">密码</td>
                <td class="window_td_left_line"> 
                  <input id="user.passwd" name="user.passwd" type="password" class="input_no_long"  maxlength="20" style="width:205px" value="<s:property value="user.passwd"/>">
                  <font color="red">&nbsp; *</font>
                </td>
              </tr>
              <tr>
                <td class="window_td_left_line">确认密码</td>
                <td class="window_td_left_line"> 
                  <input id="confirmPsw" name="confirmPsw" type="password" class="input_no_long"  maxlength="20" style="width:205px" value="<s:property value="user.passwd"/>">
                  <font color="red">&nbsp; *</font>
                </td>
              </tr>
              <tr> 
                <td width="100" class="window_td_left_line">电子邮箱</td>
                <td class="window_td_left_line"> 
                  <input id="user.email" name="user.email" type="text" class="input_no_long" size="35" maxlength="30" value="<s:property value="user.email"/>">
                  <font color="red">&nbsp; *</font>
                </td>
              </tr>
              <tr>
                <td class="window_td_left_line">角色</td>
                <td class="window_td_left_line"> 
                  <div style="word-break:break-all;width:250px; overflow:auto; ">
                  <s:combobox id="checkedRoleIds" name="checkedRoleIds" list="allRoles" listKey="id" listValue="name"/>
                  <font color="red">&nbsp; *</font>
                  </div>
                </td>
              </tr>
              <tr> 
                <td class="window_td_left_line">备注</td>
                <td class="window_td_left_line"> 
                  <textarea id="user.descn" name="user.descn" cols="50" rows="5"><s:property value="user.descn"/></textarea>
                </td>
              </tr>
              <tr> 
                <td height="30" colspan="2" align="center"> 
                	<input type="button" name="register_btn" value="注 册" class="input_submit" onClick="register();"> 
                	<input type="button" name="reset_btn" value="清 空" class="input_submit" onClick="resetAll()"> 
                	<input type="button" name="back_btn" value="返 回" class="input_submit"onClick="goBack();"> 
                </td>
              </tr>
            </table></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</form>
</body>
</html>
